<?php 
function salary_total($item,$date_work){
	/* so tien di tre ve som
	tam thoi dong di tre ve som
	if($item["type_minute_t"] == 2 || $item["type_minute_t"] == 3) // kiem tra thuoc hang muc may để trừ lấy số tiền di trễ về sớm
		$truditrevesom = ($item["salary2"]/$date_work);
	elseif($item["type_minute_t"] == 4)
		$truditrevesom = ($item["salary2"]/$date_work) +(($item["salary2"]/$date_work)/2) ;
	elseif($item["type_minute_t"] == 5)
		$truditrevesom = ($item["salary2"]/$date_work) + (($item["salary2"]/$date_work)/2) + (($item["minute_t"]- 380)*5000) ;
	else
	 */
	$truditrevesom  = 0;
	// end so tien di tre ve som
	$date_l = ($date_work == 0) ? 0 : $date_work - $item["date_n"] - $item["date_s"]; // số ngày thực tế

	/*  Di lai theo cong */
	if(!empty($item["salary_add5"]) and $item["salary_add5"]>0){
		$mucphucap 		= 0;
		$total_dilai	= $item["salary_add5"]; // di lai theo cong
	}
	else{
		$mucphucap 		= $item["salary_add2"]*$date_work;
		$total_dilai 	= $item["salary_add2"]*$date_l;
	}
	/* bao hiem cong doan */
	if($item["status"] == 1){ // ký hợp đồng tính bảo hiểm
		$baohiem  = ($item["salary"]*9.5)/100;
		$congdoan = ($item["salary"]/100);
		$baohiem_kpcd	= ($item["salary"]*21)/100;
	}
	else{
		$baohiem  = 0;
		$congdoan = 0;
		$baohiem_kpcd	= 0;
	}
	/* end bao hiem cong doan */
	/* end di lai theo cong */
	$total_tn		 = ($item["salary_add4"]/$date_work)*$date_l; // trách nhiệm;
	$luongtheocong 	 =  (($item["salary2"]/$date_work)*$date_l)+(($item["salary"]/$date_work)*$item["date_s"]) ; // luong theo ngay cong
	$hieuquacongviec = $item["salary2"] - $item["salary"];
	$tongphucap  	= $item["salary_add1"]+$total_dilai+(($item["salary_add4"]/$date_work)*$date_l) ; // tong phu cap 
	$tongthunhap    = $tongphucap + $luongtheocong+ $item["except1"];// tong phu cấp +  lương theo ngày công + bu luong 
	$total_khoantru  = $item["except5"]+$item["except4"]+$congdoan+$baohiem+$truditrevesom;// Tong_khoantru =  tam ung + cac khang tru khac + congdoan+ cong no
	$total_thuclanh = ($tongthunhap-$total_khoantru)* $item["factor"]; // thuc lanh = tong thu nhap - tong khoang tru
	return array("mucphucap"=>$mucphucap,"total_tn"=>$total_tn,"baohiem_kpcd"=>$baohiem_kpcd,"truditrevesom"=>$truditrevesom,"hieuquacongviec"=>$hieuquacongviec,"date_l"=>$date_l,"luongtheocong"=>$luongtheocong,"total_dilai"=>$total_dilai,"tongphucap"=>$tongphucap,"tongthunhap"=>$tongthunhap,"baohiem"=>$baohiem,"congdoan"=>$congdoan,"total_khoantru"=>$total_khoantru,"total_thuclanh"=>$total_thuclanh);	
}
?>